package scripts;

import bot.ScriptMethods;

public class IronPowerminer extends ScriptMethods implements Runnable {

	public void start() {
		getAccountSettings();
		System.gc();
		scriptRunning = true;
		scriptThread = new Thread(this);
		scriptThread.start();
	}

	public void stop() {
		System.gc();
		scriptRunning = false;
		scriptThread = null;
		debug("Stopped script.");
	}

	public void run() {
		while (scriptRunning) {
			try {
				handleEvents();
				int[] iron1 = getObjectById(102);
				int[] iron2 = getObjectById(103);
				if (!isSleeping()) {
					if (iron1[0] != -1) {
						atObject(iron1[1], iron1[2]);
						wait(random(600, 1000));
					} else if (iron2[0] != -1) {
						atObject(iron2[1], iron2[2]);
						wait(random(600, 1000));
					} else {
						wait(200);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public void handleEvents() throws Exception {
		if (welcomeBoxOpen())
			setWelcomeBox();
		if (!isLoggedIn())
			doLogin();
		if (getFatigue() > 80 && !isSleeping()) {
			wait(600);
			useItem(1263);
			wait(600);
		}
		if (getFatigueSleeping() < 10 && isSleeping())
			doSleeping();
		if (getFightMode() != fightMode)
			setFightMode();
	}
}